package com.wwwarehouse.usercenter.fragment.register;


import android.Manifest;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.activity.media.ClipImageActivity;
import com.wwwarehouse.common.bean.response.CardDeskTaskResponseBean;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.bean.upload.FileUploadBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.custom_widget.UIWarningRelativeLayout;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.custom_widget.textinput.TextInputLayout;
import com.wwwarehouse.common.http.NoHttpUtils;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.common.tools.PermissionUtils;
import com.wwwarehouse.common.tools.TakePhotoHelper;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.UpdateInfoListBean;
import com.wwwarehouse.usercenter.bean.response.RegisterInfoResponseBean;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.app.Activity.RESULT_OK;

/**
 * Created by mundane on 2017/08/14.
 */
@Route(path = UserCenterConstant.PATH_MODIFY_REGISTER_INFO)
public class ModifyRegisterInfoFragment extends BaseFragment implements PermissionUtils.PermissionCallbacks {

	private ImageView       mIvIdCard;
	private ImageView       mIvRegister;
	private EditText        mEtMobileCode;
	private TakePhotoHelper mTakePhotoHelper0;
	private TakePhotoHelper mTakePhotoHelper1;
	private final int PERMISSION_REQUEST_CODE_FIRST = 1;
	private final int PERMISSION_REQUEST_CODE_SECOND = 2;
	private String mCardUkid = "";
	private UIWarningRelativeLayout mWarningViewPhoto;
	private UIWarningRelativeLayout mWarningViewGender;
	private UIWarningRelativeLayout mWarningViewPhone;
	private TextInputLayout         mTilPhone;
	private EditText                mEtPhone;
	private FrameLayout             mFlCheckPhone;
	private Button                  mBtnSubmit;
//	private Handler mHandler = new Handler() {
//		@Override
//		public void handleMessage(Message msg) {
//			switch (msg.what) {
//				case 0:
//					BaseApplication.getApplicationInstance().displayRoundImgPixel("file://" + mTakePhotoHelper0.getPhotoFile().getPath(), mIvIdCard, ROUND_CORNER_RADIUS);
//					dismissProgressDialog();
//					break;
//				case 1:
//					BaseApplication.getApplicationInstance().displayRoundImgPixel("file://" + mTakePhotoHelper1.getPhotoFile().getPath(), mIvRegister, ROUND_CORNER_RADIUS);
//					dismissProgressDialog();
//					break;
//			}
//		}
//	};
	private TextView                mTvGetCode;
	private StateLayout             mStateLayout;
	private int                     ROUND_CORNER_RADIUS;
	private ImageView               mIvMale;
	private TextView                mTvMale;
	private ImageView               mIvFemale;
	private TextView                mTvFemale;
	private String                  mRegisterPath;
	private String                  mIdCardPath;
	private View                    mLlGender;
//	private TextView mTvGender;

	public ModifyRegisterInfoFragment() {
		// Required empty public constructor
	}

	public static ModifyRegisterInfoFragment newInstance() {
		ModifyRegisterInfoFragment fragment = new ModifyRegisterInfoFragment();
		Bundle args = new Bundle();
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (getArguments() != null) {

		}
		mTakePhotoHelper0 = new TakePhotoHelper(this, 0);
		mTakePhotoHelper1 = new TakePhotoHelper(this, 1);
		ROUND_CORNER_RADIUS = ConvertUtils.dip2px(getContext(), 1);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_modify_register_info, container, false);
		return view;
	}

	private CountDownTimer mCountDownTimer = new CountDownTimer(60000, 1000) {
		@Override
		public void onTick(long millisUntilFinished) {
			mTvGetCode.setText(String.format("%d秒后重发", millisUntilFinished / 1000));
		}


		@Override
		public void onFinish() {
			mTvGetCode.setText("获取验证码");
			mTvGetCode.setTextColor(getResources().getColor(R.color.common_color_c1_337cff));
			mTvGetCode.setEnabled(true);
		}
	};

	private int mUpLoadPhotoType;
	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		mStateLayout = $(R.id.slt);
		mLlGender = $(R.id.ll_gender);
//		mTvGender = $(R.id.tv_gender);
		mIvMale = $(R.id.iv_male);
		mTvMale = $(R.id.tv_male);
		mIvFemale = $(R.id.iv_female);
		mTvFemale = $(R.id.tv_female);
		mStateLayout.showProgressView(true);
		mIvRegister = $(R.id.iv_idcard);
		mIvIdCard  = $(R.id.iv_register);
		mEtMobileCode = $(R.id.et_mobile_code);
		mWarningViewPhoto = $(R.id.warning_view_photo);
		mWarningViewGender = $(R.id.warning_view_gender);
		mWarningViewPhone = $(R.id.warning_view_phone);
		mTilPhone = $(R.id.til_phone);
		mEtPhone = $(R.id.et_phone);
		mFlCheckPhone = $(R.id.fl_check_phone);
		mBtnSubmit = $(R.id.btn_submit);
		mTvGetCode = $(R.id.tv_get_code);
		mTvGetCode.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				generateSMSCode();
				mTvGetCode.setTextColor(getResources().getColor(R.color.common_color_c8_d5d7dc));
				mTvGetCode.setEnabled(false);
				mCountDownTimer.start();
			}
		});
		mBtnSubmit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// 图片出错了, 需要先上传图片
				if (!TextUtils.isEmpty(mResponseBean.faceUrl.unReason) || !TextUtils.isEmpty(mResponseBean.registerUrl.unReason)) {
					List<String> photoPathList = new ArrayList<>();
					if (mIdCardPath != null && mRegisterPath == null) {
						mUpLoadPhotoType = 1;
						photoPathList.add(mIdCardPath);
					}
					if (mIdCardPath == null && mRegisterPath != null) {
						mUpLoadPhotoType = 2;
						photoPathList.add(mRegisterPath);
					}
					if (mIdCardPath != null && mRegisterPath != null) {
						mUpLoadPhotoType = 3;
						photoPathList.add(mIdCardPath);
						photoPathList.add(mRegisterPath);
					}
					if (photoPathList.size() > 0) {
						uploadPhoto(photoPathList);
					} else {
						submitWithoutPhotopath();
					}
				} else { // 图片没出错, 不需要上传图片
					if (!TextUtils.isEmpty(mResponseBean.mobile.unReason)) { // 图片没出错, 手机号出错了, 需要先验证手机号
						mResponseBean.mobile.inviteeInfo = mEtPhone.getText().toString().trim();
						Map map = new HashMap();
						map.put("mobile", mResponseBean.mobile.inviteeInfo);
						map.put("verifycode", mEtMobileCode.getText().toString().trim());
						NoHttpUtils.httpPost(UserCenterConstant.URL_CHECK_VERIFY_CODE, map, new NoHttpUtils.OnResponseListener() {
							@Override
							public void onSucceed(CommonClass commonClass, int what) {
								switch (what) {
									case 0:
										if (TextUtils.equals("0", commonClass.getCode())) {
											Map<String, Object> hashMap = new HashMap<>();
											hashMap.put("cardUkid", mCardUkid);
											List<UpdateInfoListBean> list = new ArrayList<>();
											list.add(new UpdateInfoListBean(mResponseBean.mobile.inviteeInfo, mResponseBean.mobile.type));
											if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
												list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
											}
											hashMap.put("auditList", list);
											NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);
										} else {
											ToastUtils.showToast(commonClass.getMsg());
										}
										break;
								}
							}

							@Override
							public void onFailed(String result, int what) {
                                dismissProgressDialog();
							}

							@Override
							public void onFinish(int what) {

							}
						}, 0);
					} else { // 手机号没出错, 不需要验证手机号, 图片也没出错, 不需要验证图片
						Map<String, Object> hashMap = new HashMap<>();
						hashMap.put("cardUkid", mCardUkid);
						List<UpdateInfoListBean> list = new ArrayList<>();
						if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
							list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
						}
						hashMap.put("auditList", list);
						NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);

					}
				}
			}
		});
		mEtMobileCode.setBackgroundResource(R.drawable.shape_transparent);
	}

	private void uploadPhoto(List<String> photoPathList) {
		NoHttpUtils.httpUploadFileRequest(Constant.URL_UPLOADS_AVATAR, photoPathList, new NoHttpUtils.OnFileUploadListener() {
			@Override
			public void onStart(int position) {
				showProgressDialog();
			}

			@Override
			public void onCancel(int position) {
			}

			@Override
			public void onProgress(int position, int progress) {
			}

			@Override
			public void onFinish(int position) {
				dismissProgressDialog();
			}

			@Override
			public void onError(int position, Exception exception) {
			}
		}, new NoHttpUtils.OnFileUploadResultListener() {
			@Override
			public void onSucceed(int what, final FileUploadBean uploadBean) {
				if (TextUtils.equals("0", uploadBean.getCode())) {
					afterUploadPhoto(uploadBean);
				} else {
					toast(uploadBean.getMsg());
				}
			}

			@Override
			public void onFailed(int what, FileUploadBean uploadBean) {
				ToastUtils.showToast("图片上传失败");
			}
		});
	}

	private void submitWithoutPhotopath() {
		if (!TextUtils.isEmpty(mResponseBean.mobile.unReason)) { // 手机号出错了, 需要先验证手机号
			mResponseBean.mobile.inviteeInfo = mEtPhone.getText().toString().trim();
			Map map = new HashMap();
			map.put("mobile", mResponseBean.mobile.inviteeInfo);
			map.put("verifycode", mEtMobileCode.getText().toString().trim());
			NoHttpUtils.httpPost(UserCenterConstant.URL_CHECK_VERIFY_CODE, map, new NoHttpUtils.OnResponseListener() {
				@Override
				public void onSucceed(CommonClass commonClass, int what) {
					switch (what) {
						case 0:
							if (TextUtils.equals("0", commonClass.getCode())) {
								Map<String, Object> hashMap = new HashMap<>();
								hashMap.put("cardUkid", mCardUkid);
								List<UpdateInfoListBean> list = new ArrayList<>();
								list.add(new UpdateInfoListBean(mResponseBean.mobile.inviteeInfo, mResponseBean.mobile.type));
								if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
									list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
								}
								hashMap.put("auditList", list);
								NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);
							} else {
								ToastUtils.showToast(commonClass.getMsg());
							}
							break;
					}
				}

				@Override
				public void onFailed(String result, int what) {
					dismissProgressDialog();
				}

				@Override
				public void onFinish(int what) {

				}
			}, 0);
		} else { // 手机号没出错, 不需要验证手机号
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("cardUkid", mCardUkid);
			List<UpdateInfoListBean> list = new ArrayList<>();
			if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
				list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
			}
			hashMap.put("auditList", list);
			NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);
		}
	}

	private void afterUploadPhoto(final FileUploadBean uploadBean) {
		if (!TextUtils.isEmpty(mResponseBean.mobile.unReason)) { // 手机号出错了, 需要先验证手机号
			mResponseBean.mobile.inviteeInfo = mEtPhone.getText().toString().trim();
			Map map = new HashMap();
			map.put("mobile", mResponseBean.mobile.inviteeInfo);
			map.put("verifycode", mEtMobileCode.getText().toString().trim());
			NoHttpUtils.httpPost(UserCenterConstant.URL_CHECK_VERIFY_CODE, map, new NoHttpUtils.OnResponseListener() {
				@Override
				public void onSucceed(CommonClass commonClass, int what) {
					switch (what) {
						case 0:
							if (TextUtils.equals("0", commonClass.getCode())) {
								Map<String, Object> hashMap = new HashMap<>();
								hashMap.put("cardUkid", mCardUkid);
								List<UpdateInfoListBean> list = new ArrayList<>();
								if (mIdCardPath != null && mRegisterPath == null) {
									list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.faceUrl.type));
								}
								if (mIdCardPath == null && mRegisterPath != null) {
									list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.registerUrl.type));
								}
								if (mIdCardPath != null && mRegisterPath != null) {
									list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.faceUrl.type));
									list.add(new UpdateInfoListBean(uploadBean.getData().get(1).getPath(), mResponseBean.registerUrl.type));
								}
								list.add(new UpdateInfoListBean(mResponseBean.mobile.inviteeInfo, mResponseBean.mobile.type));
								if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
									list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
								}
								hashMap.put("auditList", list);
								NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);
							} else {
								ToastUtils.showToast(commonClass.getMsg());
							}
							break;
					}
				}

				@Override
				public void onFailed(String result, int what) {
					dismissProgressDialog();
				}

				@Override
				public void onFinish(int what) {

				}
			}, 0);
		} else { // 手机号没出错, 不需要验证手机号
			Map<String, Object> hashMap = new HashMap<>();
			hashMap.put("cardUkid", mCardUkid);
			List<UpdateInfoListBean> list = new ArrayList<>();
			if (mIdCardPath != null && mRegisterPath == null) {
				list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.faceUrl.type));
			}
			if (mIdCardPath == null && mRegisterPath != null) {
				list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.registerUrl.type));
			}
			if (mIdCardPath != null && mRegisterPath != null) {
				list.add(new UpdateInfoListBean(uploadBean.getData().get(0).getPath(), mResponseBean.faceUrl.type));
				list.add(new UpdateInfoListBean(uploadBean.getData().get(1).getPath(), mResponseBean.registerUrl.type));
			}
			if (!TextUtils.isEmpty(mResponseBean.personSex.unReason)) {
				list.add(new UpdateInfoListBean(mResponseBean.personSex.inviteeInfo, mResponseBean.personSex.type));
			}
			hashMap.put("auditList", list);
			NoHttpUtils.httpPost(UserCenterConstant.UPDATE_REGISTER_INFO, hashMap, onResponseListener, 1);
		}
	}


	/**
	 * 获取手机短信验证码
	 */
	private void generateSMSCode() {
		Map map = new HashMap();
		map.put("mobile", mEtPhone.getText().toString().trim());
		map.put("smsType", "1");
		NoHttpUtils.httpPost(UserCenterConstant.URL_GET_SMS_VERIFICATION, map, onResponseListener, 2);
	}


	private NoHttpUtils.OnFileUploadResultListener mFileUploadResultListener = new NoHttpUtils.OnFileUploadResultListener() {
		@Override
		public void onSucceed(int what, FileUploadBean uploadBean) {

		}

		@Override
		public void onFailed(int what, FileUploadBean uploadBean) {

		}
	};

	private NoHttpUtils.OnFileUploadListener mFileUploadListener = new NoHttpUtils.OnFileUploadListener() {
		@Override
		public void onStart(int position) {

		}

		@Override
		public void onCancel(int position) {

		}

		@Override
		public void onProgress(int position, int progress) {

		}

		@Override
		public void onFinish(int position) {

		}

		@Override
		public void onError(int position, Exception exception) {

		}
	};

	private void takePhoto(int requestCode) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
			// FIXME: 2017/8/22 明明不需要camera权限的, 为什么这里如果不加camera权限会报错?
			PermissionUtils.requestPermissions(ModifyRegisterInfoFragment.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, requestCode);
		} else {
			switch (requestCode) {
				case PERMISSION_REQUEST_CODE_FIRST:
					mTakePhotoHelper0.capture();
					break;
				case PERMISSION_REQUEST_CODE_SECOND:
					mTakePhotoHelper1.capture();
					break;
			}
		}
	}

	@Override
	public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
		PermissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode != RESULT_OK) {
			return;
		}
		switch (requestCode) {
			case 0:
				if (mTakePhotoHelper0.getPhotoFile() != null) {
					Intent intent = new Intent(getActivity(), ClipImageActivity.class);
					intent.putExtra("key_select_image_path", mTakePhotoHelper0.getPhotoFile().getPath());
					startActivityForResult(intent, 2);
				}
				break;
			case 1:
				if (mTakePhotoHelper1.getPhotoFile() != null) {
					Intent intent = new Intent(getActivity(), ClipImageActivity.class);
					intent.putExtra("key_select_image_path", mTakePhotoHelper1.getPhotoFile().getPath());
					startActivityForResult(intent, 3);
				}
				break;
			case 2:
				// mTakePhotoHelper0
				mIdCardPath = data.getStringExtra("key_select_image_path");
				mIvIdCard.setImageBitmap(BitmapFactory.decodeFile(mIdCardPath));
//				ImageloaderUtils.displayFileImage(mIdCardPath, mIvIdCard);

				break;
			case 3:
				// mTakePhotoHelper1
				mRegisterPath = data.getStringExtra("key_select_image_path");
				mIvRegister.setImageBitmap(BitmapFactory.decodeFile(mRegisterPath));
//				ImageloaderUtils.displayFileImage(mRegisterPath, mIvRegister);

				break;
			default:
				break;
		}
	}

	// 防止内存泄露
	@Override
	public void onDestroy() {
//		if (mHandler != null) {
//			mHandler.removeCallbacksAndMessages(null);
////			mHandler = null;
//		}
		if (mCountDownTimer != null) {
			mCountDownTimer.cancel();
		}
		super.onDestroy();
	}

	@Override
	public void setTitle() {
		if (peekFragment() instanceof ModifyRegisterInfoFragment) {
			mActivity.setTitle("修改注册信息");
		}
	}

	@Override
	public void requestDatas() {
		if(getArguments() != null) {
			CardDeskTaskResponseBean.TaskBean mTaskDetails = (CardDeskTaskResponseBean.TaskBean) getArguments().getSerializable(Constant.KEY_CARD_DESK_TASK_DETAILS);
			if(mTaskDetails != null)
				mCardUkid = mTaskDetails.getCardUkid();
		}
		Map<String, String> map = new HashMap<>();
		map.put("cardUkid", mCardUkid);
		NoHttpUtils.httpPost(UserCenterConstant.GET_AUDIT_REGISTER_INFO, map, onResponseListener, 0);
	}

	@Override
	public void onResume() {
		super.onResume();
		Constant.isTakePhotoFinished = true;
	}

	private RegisterInfoResponseBean mResponseBean;

	NoHttpUtils.OnResponseListener onResponseListener = new NoHttpUtils.OnResponseListener() {
		@Override
		public void onSucceed(CommonClass commonClass, int what) {
			switch (what) {
				case 0:
					if (TextUtils.equals("0", commonClass.getCode())) {
						mStateLayout.showContentView();
						mResponseBean = JSON.parseObject(commonClass.getData().toString(), RegisterInfoResponseBean.class);
						BaseApplication.getApplicationInstance().displayRoundImgPixel(mResponseBean.faceUrl.inviteeInfo, mIvIdCard, ROUND_CORNER_RADIUS);
						BaseApplication.getApplicationInstance().displayRoundImgPixel(mResponseBean.registerUrl.inviteeInfo, mIvRegister, ROUND_CORNER_RADIUS);
						if (TextUtils.isEmpty(mResponseBean.faceUrl.unReason) && TextUtils.isEmpty(mResponseBean.registerUrl.unReason)) {
							mIvIdCard.setImageAlpha(0x4D);
							mIvRegister.setImageAlpha(0x4D);
						} else {
							mWarningViewPhoto.setStateWarning(true);
							mIvIdCard.setOnClickListener(new View.OnClickListener() {
								@Override
								public void onClick(View v) {
									Constant.isTakePhotoFinished = false;
									takePhoto(PERMISSION_REQUEST_CODE_FIRST);
								}
							});

							mIvRegister.setOnClickListener(new View.OnClickListener() {
								@Override
								public void onClick(View v) {
									takePhoto(PERMISSION_REQUEST_CODE_SECOND);
								}
							});
						}

						if (TextUtils.isEmpty(mResponseBean.personSex.unReason)) { // 性别不需要修改
							if (TextUtils.equals("男", mResponseBean.personSex.inviteeInfo)) {
								mIvMale.setImageResource(R.drawable.radio_check_disable);
								mIvFemale.setImageResource(R.drawable.radio_uncheck);
							} else {
								mIvMale.setImageResource(R.drawable.radio_uncheck);
								mIvFemale.setImageResource(R.drawable.radio_check_disable);
							}
							mTvMale.setTextColor(getResources().getColor(R.color.common_color_c8_d5d7dc));
							mTvFemale.setTextColor(getResources().getColor(R.color.common_color_c8_d5d7dc));
						} else { // 性别需要修改
							mWarningViewGender.setStateWarning(true);
							if (TextUtils.equals("男", mResponseBean.personSex.inviteeInfo)) {
								mIvMale.setImageResource(R.drawable.radio_check_enable);
								mIvFemale.setImageResource(R.drawable.radio_uncheck);
								mResponseBean.personSex.inviteeInfo = "男";
							} else {
								mIvFemale.setImageResource(R.drawable.radio_check_enable);
								mIvMale.setImageResource(R.drawable.radio_uncheck);
								mResponseBean.personSex.inviteeInfo = "女";
							}
							mIvMale.setOnClickListener(maleListener);
							mTvMale.setOnClickListener(maleListener);
							mIvFemale.setOnClickListener(femaleListener);
							mTvFemale.setOnClickListener(femaleListener);
							mTvMale.setTextColor(getResources().getColor(R.color.common_color_c4_121417));
							mTvFemale.setTextColor(getResources().getColor(R.color.common_color_c4_121417));
						}

						if (TextUtils.isEmpty(mResponseBean.mobile.unReason)) {
//							mEtPhone.setEnabled(false);
							// 这个一定要放在setHint前面
							mTilPhone.setEnabled(false);
							mEtPhone.setHint(mResponseBean.mobile.inviteeInfo);
							mFlCheckPhone.setVisibility(View.GONE);
						} else {
							mWarningViewPhone.setStateWarning(true);
							mEtPhone.setText(mResponseBean.mobile.inviteeInfo);
							mTilPhone.showLableView();
						}

					} else {
						ToastUtils.showToast(commonClass.getMsg());
					}
					break;
				case 1:
					if (TextUtils.equals("0", commonClass.getCode())) {
//						ToastUtils.showToast(commonClass.getMsg());
						popFragment();
						pushFragment(AlreadySubmitFragment.newInstance(mResponseBean.inviteMobile));
					} else {
						ToastUtils.showToast(commonClass.getMsg());
					}
					break;
				case 2:
					if (TextUtils.equals("0", commonClass.getCode())) {
						Toast.makeText(mActivity, "验证码已发送", Toast.LENGTH_SHORT).show();
					} else {
						ToastUtils.showToast(commonClass.getMsg());
					}
					break;
			}
		}

		@Override
		public void onFailed(String result, int what) {
		}

		@Override
		public void onFinish(int what) {
			dismissProgressDialog();
		}
	};

	private View.OnClickListener maleListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			mIvMale.setImageResource(R.drawable.radio_check_enable);
			mIvFemale.setImageResource(R.drawable.radio_uncheck);
			mResponseBean.personSex.inviteeInfo = "男";
		}
	};

	private View.OnClickListener femaleListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			mIvFemale.setImageResource(R.drawable.radio_check_enable);
			mIvMale.setImageResource(R.drawable.radio_uncheck);
			mResponseBean.personSex.inviteeInfo = "女";
		}
	};

	@Override
	public void onPermissionsGranted(int requestCode, List<String> perms) {
		if (perms.size() == 2) {
			switch (requestCode) {
				case PERMISSION_REQUEST_CODE_FIRST:
					mTakePhotoHelper0.capture();
					break;
				case PERMISSION_REQUEST_CODE_SECOND:
					mTakePhotoHelper1.capture();
					break;
			}
		}
	}

	@Override
	public void onPermissionsDenied(int requestCode, List<String> perms) {
		if (requestCode == PERMISSION_REQUEST_CODE_FIRST) {
			PermissionUtils.permissionDialog(mActivity, perms, null);
		}
	}
}
